<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>青岛政务AI应用</title>
    <style>
        html {
            height: 100%;
            overflow: hidden;
        }
        /* 全局样式 */
        body {
            height: 100%;
            padding: 20px 0;
            box-sizing: border-box;
            font-family: Arial, sans-serif;
            margin: 0;
            background-color: #f5f5f5;
        }

        /* 标题栏 */
        /*.header {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0% 1% 0% 1%;
            !*background-color: #007bff;*!
            background: url("./bb1.png") no-repeat;
            color: #fff;
            height: 7vh;
            !*padding: 20px;*!
            text-align: left;
            !*line-height: 30px;*!
            font-size: 24px;
            font-weight: bold;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }*/

        /* 页面分为上下两部分 */
        .top-section, .bottom-section {
            width: 100%;
            max-width: 1200px;
            margin: 0 auto 20px;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .bottom-section {
            display: flex
        ;
            flex-direction: row;
            gap: 20px;
            height: calc(100% - 140px);
            margin: 0 auto;
        }

        /* 按钮样式 */
        .button {
            padding: 10px 20px;
            margin-right: 10px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
        }

        .button.primary {
            background-color: #007bff;
            color: #fff;
        }

        .button.primary:hover {
            background-color: #0056b3;
        }

        .button.success {
            background-color: #28a745;
            color: #fff;
        }

        .button.success:hover {
            background-color: #218838;
        }

        /* 文件名称显示框 */
        .file-name-box {
            display: inline-block;
            padding: 10px;
            margin-left: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f9f9f9;
            font-size: 14px;
        }

        /* 正文内容展示 */
        .content-section {
            max-height: 100%;
            flex: 1;
            /* height: calc(100% - 80px); */
            overflow: auto;
            /*width: 100%;*/
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f9f9f9;
        }

        .content-section .content {
            white-space: pre-wrap; /* 保留换行和空格 */
            line-height: 1.5;
            font-size: 20px;
        }

        .content-section .error {
            background-color: #ffebee; /* 错误内容背景色 */
            color: #c62828; /* 错误内容文字颜色 */
            padding: 2px 4px;
            border-radius: 3px;
            font-size: 20px;
        }

        /* 审核结果表格 */
        .result-table {
            width: 100%;
            border-collapse: collapse;
            overflow: auto;
            margin-top: 20px;
        }

        .result-table th,
        .result-table td {
            padding: 10px;
            border: 1px solid #ddd;
            text-align: left;
        }

        .result-table th {
            background-color: #d8ecff;
            color: #0f0f0f;
            font-weight: bold;
        }

        .result-table tr:nth-child(even) {
            background-color: #f9f9f9;
        }

        /* 加载中弹窗 */
        .loading-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            justify-content: center;
            align-items: center;
        }

        .loading-content {
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            text-align: center;
        }

        .table-row {
            width: 96px;
            text-align: center;
        }

        .table-row-64 {
            width: 64px;
            text-align: center;
        }
        .result-section{
            width: 330px;
            overflow: auto;
        }
    </style>
</head>
<body>
<!-- 标题栏 -->
<!--<div class="header">
   <div style="display: flex;align-items: center;height: 4vh">
       <img src="./gh.png" height="30">
       <div>青岛政务AI应用</div>
   </div>
    <div>
        <img src="./tx.png">
    </div>
</div>-->

<!-- 第一部分：按钮区域 -->
<div class="top-section">
    <button class="button primary" onclick="clearContentAndResults(); document.getElementById('file-upload').click()">选择文件</button>
    <div class="file-name-box" id="file-name-box">未选择文件</div>
    <button class="button success" onclick="parseFile()">解析文件</button>
    <input type="file" id="file-upload" style="display: none;">
</div>

<!-- 第二部分：正文内容和审核结果 -->
<div class="bottom-section">
    <!-- 正文内容展示 -->
    <div class="content-section">
        <h2>文件内容</h2>
        <div class="content" id="content"></div>
    </div>

    <!-- 审核结果展示 -->
    <div class="result-section">
        <h3>审核结果</h3>
        <table class="result-table" id="result-table">
            <!--<thead>
            <tr>
                <th class="table-row-64">公文标题</th>
                <th class="table-row">篇幅是否合规</th>
                <th class="table-row">附件是否齐全</th>
                <th class="table-row">信息准确程度</th>
                <th class="table-row">要素是否齐全</th>
                <th class="table-row">满足条例规定</th>
                <th class="table-row">文理是否规范</th>
            </tr>
            </thead>
            <tbody>
            &lt;!&ndash; 审核结果动态填充 &ndash;&gt;
            &lt;!&ndash; 审核结果动态填充 &ndash;&gt;
            <tr>
                <td class="table-row-64">-</td>
                <td class="table-row">-</td>
                <td class="table-row">-</td>
                <td class="table-row">-</td>
                <td class="table-row">-</td>
                <td class="table-row">-</td>
                <td class="table-row">-</td>
            </tr>
            </tbody>-->
            <thead>
                <tr>
                    <th class="table-row-64">公文标题</th>
                </tr>
            </thead>
            <tbody>
                <!-- 审核结果动态填充 -->
                <!-- 审核结果动态填充 -->
                <tr>
                    <td class="table-row-64 table-content-1">-</td>
                </tr>
            </tbody>

            <thead>
                <tr>
                    <th class="table-row">篇幅是否合规</th>
                </tr>
            </thead>

            <tbody>
                <!-- 审核结果动态填充 -->
                <!-- 审核结果动态填充 -->
                <tr>
                    <td class="table-row table-content-2">-</td>
                </tr>
            </tbody>



            <thead>
                <tr>
                    <th class="table-row-64">附件是否齐全</th>
                </tr>
            </thead>
            <tbody>
            <!-- 审核结果动态填充 -->
            <!-- 审核结果动态填充 -->
                <tr>
                    <td class="table-row table-content-3">-</td>
                </tr>
            </tbody>
            <thead>
                <tr>
                    <th class="table-row-64">信息准确程度</th>
                </tr>
            </thead>
            <tbody>
                <!-- 审核结果动态填充 -->
                <!-- 审核结果动态填充 -->
                <tr>
                    <td class="table-row table-content-4">-</td>
                </tr>
            </tbody>
            <thead>
                <tr>
                    <th class="table-row-64">要素是否齐全</th>
                </tr>
            </thead>
            <tbody>
            <!-- 审核结果动态填充 -->
                <!-- 审核结果动态填充 -->
                <tr>
                    <td class="table-row table-content-5">-</td>
                </tr>
            </tbody>
            <thead>
                <tr>
                    <th class="table-row-64">满足条例规定</th>
                </tr>
            </thead>
            <tbody>
            <!-- 审核结果动态填充 -->
            <!-- 审核结果动态填充 -->
            <tr>
                <td class="table-row table-content-6">-</td>
            </tr>
            </tbody>
            <thead>
            <tr>
                <th class="table-row-64">文理是否规范</th>
            </tr>
            </thead>
            <tbody>
            <!-- 审核结果动态填充 -->
            <!-- 审核结果动态填充 -->
            <tr>
                <td class="table-row table-content-7">-</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<!-- 加载中弹窗 -->
<div class="loading-modal" id="loading-modal">
    <div class="loading-content">
        <p>大模型处理中...</p>
    </div>
</div>

<script>
    // 文件上传逻辑
    const fileUpload = document.getElementById('file-upload');
    const fileNameBox = document.getElementById('file-name-box');
    const contentDiv = document.getElementById('content');
    const resultTableBody = document.querySelector('#result-table tbody');


    // 新增函数：清空正文内容和解析结果
    function clearContentAndResults() {
        // 清空正文内容
        contentDiv.innerHTML = '';
        // 清空审核结果表格
        document.getElementsByClassName('table-content-1')[0].textContent = '-';
        document.getElementsByClassName('table-content-2')[0].textContent = '-';
        document.getElementsByClassName('table-content-3')[0].textContent = '-';
        document.getElementsByClassName('table-content-4')[0].textContent = '-';
        document.getElementsByClassName('table-content-5')[0].textContent = '-';
        document.getElementsByClassName('table-content-6')[0].textContent = '-';
        document.getElementsByClassName('table-content-7')[0].textContent = '-';
    }

    fileUpload.addEventListener('change', function (event) {
        const file = event.target.files[0];
        if (file) {
            // 显示文件名
            fileNameBox.textContent = file.name;
        } else {
            fileNameBox.textContent = '未选择文件';
        }
        console.log(resultTableBody);
    });

    // 解析文件逻辑
    function parseFile() {
        const file = fileUpload.files[0];
        if (!file) {
            alert('请先选择文件');
            return;
        }

        // 显示加载中弹窗
        const loadingModal = document.getElementById('loading-modal');
        loadingModal.style.display = 'flex';

        // 模拟后端请求（替换为实际的后端URL）
        const backendUrl = '/parse'; // 替换为实际的后端URL
        const formData = new FormData();
        formData.append('file', file);

        fetch(backendUrl, {
            method: 'POST',
            body: formData
        })
            .then(response => response.json())
            .then(data => {
                // 隐藏加载中弹窗
                loadingModal.style.display = 'none';

                // 更新正文内容
                if (data.result) {
                    contentDiv.innerHTML = highlightErrors(data.result.fileContent, data.result.errorcontent);
                }

                // 更新审核结果表格
                // 更新审核结果表格
                if (data.result) {
                    console.log('1',data.result)
                    const resulta = data.result;
                    document.getElementsByClassName('table-content-1')[0].textContent = resulta.docTitle || '-';
                    document.getElementsByClassName('table-content-2')[0].textContent = resulta.islengthcompliance || '-';
                    document.getElementsByClassName('table-content-3')[0].textContent = resulta.iscompletionlevel || '-';
                    document.getElementsByClassName('table-content-4')[0].textContent = resulta.accuracyinformation || '-';
                    document.getElementsByClassName('table-content-5')[0].textContent = resulta.isCompleteelements || '-';
                    document.getElementsByClassName('table-content-6')[0].textContent = resulta.ismeetrequirements || '-';
                    document.getElementsByClassName('table-content-7')[0].textContent = resulta.isunitycoherence || '-';

                    /*return
                    const resulta = data.result; // 假设后端返回一个结果对象
                    resultTableBody.innerHTML = `
                        <tr>
                            <td>${resulta.docTitle || '-'}</td>
                        </tr>
                        <tr>
                            <td>${resulta.islengthcompliance || '-'}</td>
                        </tr>
                        <tr>

                            <td>${resulta.accuracyinformation || '-'}</td>

                        </tr>
                        <tr>

                            <td>${resulta.isCompleteelements || '-'}</td>

                        </tr>
                        <tr>

                            <td>${resulta.ismeetrequirements || '-'}</td>

                        </tr>
                        <tr>

                            <td>${resulta.isunitycoherence || '-'}</td>
                        </tr>
                    `;*/
                }
            })
            .catch(error => {
                // 隐藏加载中弹窗
                loadingModal.style.display = 'none';
                alert('解析失败，请重试');
                console.error('Error:', error);
            });
    }

    // 高亮显示错误内容
    function highlightErrors(content, errors) {
        if (!errors || errors.length === 0) return content;

        let highlightedContent = content;
        errors.forEach(error => {
            const { start, end } = error; // 错误内容的起始和结束位置
            const errorText = content.slice(start, end);
            highlightedContent = highlightedContent.replace(
                errorText,
                `<span class="error">${errorText}</span>`
            );
        });
        return highlightedContent;
    }
</script>
</body>
</html>